package quanlydoanvao.themmoi;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import quanlydoanra.utils.truyXuatDatabase;
import utils.DateUtils;
import dbutil.ConnectDB;

public class VanBanDen {
	private int id;
	private String soVB;
	private String cqDeNghi;
	private java.util.Date ngayXuatVB;
	private String noiDungVBD;
	private String moTaVBD;
	
	public VanBanDen() {	
	}


	public VanBanDen(String soVB, String cqDeNghi, Date ngayXuatVB,
			String noiDungVBD, String moTaVBD) {
		super();
		this.soVB = soVB;
		this.cqDeNghi = cqDeNghi;
		this.ngayXuatVB = ngayXuatVB;
		this.noiDungVBD = noiDungVBD;
		this.moTaVBD = moTaVBD;
	}


	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}


	public String getSoVB() {
		return soVB;
	}


	public void setSoVB(String soVB) {
		this.soVB = soVB;
	}


	public String getCqDeNghi() {
		return cqDeNghi;
	}


	public void setCqDeNghi(String cqDeNghi) {
		this.cqDeNghi = cqDeNghi;
	}


	public java.util.Date getNgayXuatVB() {
		return ngayXuatVB;
	}


	public void setNgayXuatVB(java.util.Date ngayXuatVB) {
		this.ngayXuatVB = ngayXuatVB;
	}


	public String getNoiDungVBD() {
		return noiDungVBD;
	}


	public void setNoiDungVBD(String noiDungVBD) {
		this.noiDungVBD = noiDungVBD;
	}


	public String getMoTaVBD() {
		return moTaVBD;
	}


	public void setMoTaVBD(String moTaVBD) {
		this.moTaVBD = moTaVBD;
	}
	public int insertVBDen(){
		try{
		java.sql.Date sqlDate =  DateUtils.utilDateToSqlDate(this.ngayXuatVB);	
		String sql2 = "insert into vanbanden(sovb,ngayxuatvb,coquandenghi,noidung, motaqd) values('"+this.soVB+"','"+sqlDate+"','"+this.cqDeNghi+"','"+this.noiDungVBD+"','"+this.moTaVBD+"')";
		System.out.println(sql2);
		int idVBDen = truyXuatDatabase.insertData(sql2);
		
		if(idVBDen == 1){
			String sql1 = "select * from vanbanden where sovb = '"+this.soVB+"' and ngayxuatvb = '"+this.ngayXuatVB+"'";
			ArrayList arr = ConnectDB.getDataTypeList(sql1);
			HashMap<String, Object> hash = (HashMap<String, Object>) arr.get(0);
			int id = Integer.parseInt(hash.get("id").toString());
			System.out.println("id VB Den"+id);
			this.id = id;
		}
		}
		catch(Exception ex){
			System.out.println("Loi ");
		}
	return this.id;
		
	}

}
